﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using compshop;
using System.Data.Services;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Data.Services.Common;



namespace CompShop.WCFDataService
{
    public class CompShopDataService : DataService<CompShopEntities>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*",ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            //config.            DataServiceProtocolVersion.V2;
        }

        [WebGet]
        [SingleResult]
        public int? AddProductFromSupplier(int genProductID, int count, int department, DateTime shipDate, double purchasePrice)
        {
            System.Data.Objects.ObjectResult<int?> a;
            try
            {
               a = CurrentDataSource.AddProductFromSupplier(genProductID, count, department, shipDate, (decimal)purchasePrice);
                // res = CurrentDataSource.AddProductFromSupplier(genProductID, count, department,  shipDate, (decimal)purchasePrice);
            }
            catch (Exception ex)
            {
                return -1;
            }           
            return a.First();
        }

        [WebGet]
        [SingleResult]
        public int AddProductToOrder(int orderID, int productID, int count)
        {
            int res = 0;
            try
            {
                //CurrentDataSource.AddOneProductToOrder(orderID, productID);
            }
            catch (Exception ex)
            {
                return -1;
            }
            return res;
        }
      
    }
}
